#!/bin/bash

# Get dependencies
# obtain model and jetson_model
get_model &>/dev/null
if [[ -z "$jetson_model" ]] && [ ! -z "$__cpu_op_mode_32" ]; then
  sudo dpkg --add-architecture armhf
  bedrock_depends=()
  if package_available libasound2t64:armhf; then
    bedrock_depends+=('libasound2t64:armhf')
  else
    bedrock_depends+=('libasound2:armhf')
  fi
  install_packages "${bedrock_depends[@]}" libx11-6:armhf libxext6:armhf libegl1:armhf zlib1g:armhf libstdc++6:armhf libgl1-mesa-dri:armhf libpulse0:armhf libcom-err2:armhf libgmp10:armhf libp11-kit0:armhf libsystemd0:armhf || exit 1
else
  warning "Your system is only capable of running the ARM64 versions of Minecraft Bedrock. You will be unable to run older ARM32 versions of Minecraft Bedrock that you may find in this launcher."
fi

#Download file
mkdir -p ~/.local/bin || error "Could not make directory"
if package_is_new_enough libc6 2.36 ;then
  wget -O ~/.local/bin/MCBedrock.AppImage 'https://github.com/minecraft-linux/appimage-builder/releases/download/v0.14.2-792/Minecraft_Bedrock_Launcher-bookworm-arm64-v0.14.2.792.AppImage' || error "failed to download Minecraft Bedrock Launcher"
else
  wget -O ~/.local/bin/MCBedrock.AppImage 'https://github.com/minecraft-linux/appimage-builder/releases/download/v0.14.2-792/Minecraft_Bedrock_Launcher-arm64-v0.14.2.792.AppImage' || error "failed to download Minecraft Bedrock Launcher"
fi
chmod +x ~/.local/bin/MCBedrock.AppImage

enable_module fuse || exit 1

#Make Desktop file
mkdir -p ~/.local/share/applications
echo "[Desktop Entry]
Version=1.1
Type=Application
Name=Minecraft Bedrock Launcher
Comment=A Minecraft: Bedrock Edition
Icon=$(dirname "$0")/icon-64.png
Exec=env GALLIUM_HUD=simple,fps $HOME/.local/bin/MCBedrock.AppImage
Categories=Game;
Terminal=false
StartupNotify=true" > ~/.local/share/applications/minecraftbedrock.desktop
